package com.usian.behavior.service.impl;

import com.usian.behavior.mapper.ApFollowBehaviorMapper;
import com.usian.behavior.service.ApBehaviorEntryService;
import com.usian.behavior.service.ApFollowBehaviorService;
import com.usian.model.base.BaseServiceImpl;
import com.usian.model.behavior.dtos.FollowBehaviorDto;
import com.usian.model.behavior.pojos.ApBehaviorEntry;
import com.usian.model.behavior.pojos.ApFollowBehavior;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ApFollowBehaviorServiceImpl extends BaseServiceImpl<ApFollowBehaviorMapper, ApFollowBehavior> implements ApFollowBehaviorService {


    @Autowired
    private ApBehaviorEntryService apBehaviorEntryService;

    @Override
    public ResponseResult saveFollowBehavior(FollowBehaviorDto dto) {

        ApBehaviorEntry apBehaviorEntry = apBehaviorEntryService.findByUserIdOrEquipmentId(dto.getUserId(), null);

        if (apBehaviorEntry == null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }

        //保存关注行为
        ApFollowBehavior behaviorEntry = new ApFollowBehavior();
        behaviorEntry.setEntryId(dto.getUserId());
        behaviorEntry.setFollowId(dto.getFollowId());
        behaviorEntry.setArticleId(dto.getArticleId());
        behaviorEntry.setCreatedTime(new Date());

        return okResult(save(behaviorEntry));

    }

}
